package autorization;

import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * the Interface which all classes intended for should realise
 * uses as the authorisation table
 * @author Volk ID = 1001
 * @version 0.1 Добавлен базовый функционал
 * @version 0.2 Проведена интеграция с системой ролей, добавлены сервисы для работы с ролями пользователя
 */
public interface IAutorization {
    public final int IMPORT_CURRENT = 0; //There is an overwriting of the imported table of authorisation in the current table.
    public final int IMPORT_NEW = 1; //The import File becomes a current file. There is a change of a directory of a file containing the authorisation table on an input file directory.

    /**
     * to Register the user
     * @param login - a login, the user
     * @param password - the password
     * @return - the system identifier of the registered user
     * @throws RegistrationFailed - in a case if parametres is null-values
     * or the user with such login is already registered, the exception of the given type is generated
     */

    public long Registration(String login, String password, long role_id) throws RegistrationFailed,IOException;
  /**
     * Removal of the accounting record of the user
     * @param ID - the system identifier of the user
     * @return false - in a case if the user with the set system identifier does not exist
     * true - in a case if removal is successfully executed
     */
    public boolean unregistration(long ID) throws IOException;
    /**
     * Carries out check, - whether the user in system is registered
     * @param login - a login of the user
     * @param Password - the password of the user
     * @return true - if user is registered in table, else - false
     * @throws autorization. RegistrationFailed if the login or the password are specified incorrectly,
     * there is an exception of the given type
     */
    public boolean isRegistration(String login, String Password);

    /**
     * returns user's identifier by selected login and password
     * @param login - user's login
     * @param Password - user's password
     * @return user's identifier
     * @throws autorization.RegistrationFailed  if the login or the password are specified incorrectly,
     * there is an exception of the given type
     */
    public long getID(String login, String Password) throws RegistrationFailed;
    /**
     * To remove all users accounts
     */
    public void clear() throws IOException;
    /**
     * Allows to modify the registered login, on the active system identifier
     * @param ID - the system identifier
     * @param NewLogin - a new login
     * @return true - login replacement has gone right, false - in login change is given up
     * in a consequence of not registered system identifier
     * @throws autorization. RegistrationFailed - the login on which is made attempt to change
     * the old login is already registered in system
     */
    public boolean modifyLogin(long lID, String NewLogin) throws RegistrationFailed,IOException;
     /**
     * Allows the user to change the own password
     * @param ID - the system identifier of the user
     * @param NewPassword - the new password
     * @return true - in case of successful performance of operation,
     * false - in case the user with the set system identifier
     * it is not registered in system
     * @throws autorization. RegistrationFailed - in case parametre NewPassword
     * it is equal to null-value
     */
    public boolean modifyPassword(long lID, String NewPassword) throws RegistrationFailed,IOException;

    /**
     * To get the path to file of autorization table
     * @return path
     */
    public String getPath();

    //------------------Методы для работы с ролью пользователя------------------
    /**
     * Получить идентификатор роли пользователя 
     * @param login - логин пользователя
     * @return идентификатор роли пользователя
     */
    public long getRole(String login);

    /**
     * Получить идентификатор роли пользователя
     * @param ID - идентификатор пользователя
     * @return идентификатор роли пользователя
     */
    public long getRole(long ID);

    /**
     * Присвоить пользователя новую роль
     * @param login - логин
     * @param NewRoleID - идентификатор назначаемой роли
     * @return true - установка прошла удачно, false пользователя с таким логином не существует в системе
     */
    public boolean setRoleID(String login, long NewRoleID);

    /**
     * Присвоить пользователя новую роль
     * @param ID - идентификатор поьзователя
     * @param NewRoleID - идентификатор назначаемой роли
     * @return true - установка прошла удачно, false пользователя с таким логином не существует в системе
     */
    public boolean setRoleID(long ID, long NewRoleID);
    //--------------------------------------------------------------------------

    /**
    * Count of registered users
    * @return size
    */
    public int getSize();

    /**
     * To import information from file
     * @param path - path to file contents autorization infromation.
     * @param typeImport Can trample down values of one of following constants of interface IAutorization:
     *        IMPORT_CURRENT or IMPORT_NEW.
     * @throws java.io.IOException input-output error
     * @throws java.io.FileNotFoundException entry file is not file
     * @throws autorization.FormatException The file format does not correspond to a format supported by the given version of the program
     */
    public void Import(String path, int typeImport) throws FormatException,FileNotFoundException,IOException;

     /**
        * to Receive the interface on iterator for the current table of authorisation
        * @return the interface on iterator for the current table of authorisation
      */
    public IAutorizationIterator getIterator();
}